/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package replica;

import generalResourceLalla.Utilities;
import java.util.logging.Logger;
import generalResourceLalla.logging.LoggerFactory;
import java.io.File;

/**
 *
 * @author andrea
 */
public class ReplicaLoggerFactory 
{
    public static final String LOG_PARENT_FOLDER="files/logs/replica/";
    
    public static String getNodeFolder(long nodeId)
    {
        return LOG_PARENT_FOLDER+"node_"+nodeId+"/";
    }
    
    
    
    public static void cleanServerLogFolder()
    {
        Utilities.emptyFolder(LOG_PARENT_FOLDER+"server");
        File parentFolder=new File(LOG_PARENT_FOLDER);
        if (parentFolder.exists())
            for(File nodeFolder:parentFolder.listFiles())
                Utilities.emptyFolder(nodeFolder.getPath(), "frontEnd");
    }
    
    
    
    public static void cleanHostLogFolder()
    {
        Utilities.emptyFolder(LOG_PARENT_FOLDER+"server");
        File parentFolder=new File(LOG_PARENT_FOLDER);
        if (parentFolder.exists())
            for(File nodeFolder:parentFolder.listFiles())
                Utilities.emptyFolder(nodeFolder.getPath(), "replicaManager");
    }
    
    public static Logger getReplicaServerCommunicationLogger(int life) {
        return LoggerFactory.getLogger(
                0, "ReplicaServer ", LOG_PARENT_FOLDER+"server/replica_srv_comm", life);
    }

    public static Logger getReplicaHostCommunicationLogger(int life) {
        return LoggerFactory.getLogger(
                0, "ReplicaHost ", LOG_PARENT_FOLDER+"host/replica_host_comm", life);
    }

    public static Logger getReplicaManagerLogger(long nodeId, long replicaHostId,int life) {
        return LoggerFactory.getLogger(
                nodeId, "ReplicaManager on host "+replicaHostId+
                " of node ", getNodeFolder(nodeId)+"replicaManagerOnHost_"+replicaHostId, life);
    }

    public static Logger getFrontEndLogger(long nodeId, int life) {
        return LoggerFactory.getLogger(
                nodeId, "FrontEnd ", getNodeFolder(nodeId)+"frontEnd", life);
    }
    
    public static Logger getPendingOperationLogger(long nodeId, int life) {
        return LoggerFactory.getLogger(
                nodeId, "Pending operations ", getNodeFolder(nodeId)+"pendingOperations", life);
    }
    
    public static Logger getFrontEndStateMachineLogger(long nodeId, int life) {
        return LoggerFactory.getLogger(
                nodeId, "FrontEndStateMachine ", getNodeFolder(nodeId)+"frontEndStateMachine", life);
    }
    
    public static Logger getReplicaManagerStateMachineLogger(long nodeId, long replicaHostId,int life) {
        return LoggerFactory.getLogger(
                nodeId, "ReplicaManagerStateMachine on host "+replicaHostId+
                " of node ", getNodeFolder(nodeId)+"replicaManagerStateMachineOnHost_"+replicaHostId, life);
    }
}
